﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1.集合
{
    public class Class1
    {
        public static void Test()
        {
            ArrayList arrayList = new ArrayList();
            arrayList.Add(1);
            arrayList.Add("hello world");
            arrayList.Add(new { Id=1,Name="wbd"});

            //DataTable dt = new DataTable();
            //dt.Columns.Add("Id",typeof(int));
            //dt.Columns.Add("Name", typeof(string));

            //DataColumn dc = new DataColumn();
            //dt.Columns.Add(dc);
            ////2.创建带列名和类型名的列(两种方式任选其一)
            //dt.Columns.Add("column0", System.Type.GetType("System.String"));
            //dt.Columns.Add("column1", typeof(String));

            //DataColumn col = new DataColumn("column2", typeof(DateTime));
            //DataRow dr= dt.NewRow();
            //dr[0] = 1;
            //dr[2] = 2;



            DataTable dt = new DataTable();//创建表
            dt.Columns.Add("ID", typeof(Int32));//添加列
            dt.Columns.Add("Name", typeof(String));
            dt.Columns.Add("Age", typeof(Int32));
            dt.Rows.Add(new object[] { 1, "张三", 20 });//添加行
            dt.Rows.Add(new object[] { 2, "李四", 25 });
            dt.Rows.Add(new object[] { 3, "王五", 30 });
            DataView dv = dt.DefaultView;//获取表视图
            dv.Sort = "ID DESC";//按照ID倒序排序
            dv.ToTable();//转为表
        }
    }
}
